<?php require('connections/con_gl.php'); ?>

<?php

cekAkses($_SESSION[akses],"PD-3");

$currentPage = $_SERVER["PHP_SELF"];



mysql_select_db($database_con_gl, $con_gl);

$query_l_kel = "SELECT id, kelompok FROM gl_kelompok ORDER BY kelompok ASC";

$l_kel = mysql_query($query_l_kel, $con_gl) or die(mysql_error());

$row_l_kel = mysql_fetch_assoc($l_kel);

$totalRows_l_kel = mysql_num_rows($l_kel);



$maxRows_data = 8;

$pageNum_data = 0;

if (isset($_GET['pageNum_data'])) {

  $pageNum_data = $_GET['pageNum_data'];

}

$startRow_data = $pageNum_data * $maxRows_data;

$cr_txt = str_replace("+"," ",$_REQUEST[cr_txt]);

mysql_select_db($database_con_gl, $con_gl);

$query_data = "SELECT gl_barang.id, gl_barang.barang, gl_barang.keterangan, gl_kelompok.kelompok FROM gl_barang, gl_kelompok WHERE gl_kelompok.id = gl_barang.kelompok";

if(isset($_GET[cr_txt]) AND $_GET[cr_txt]<>'' AND $_GET[cr_txt]<>'+') { 

$decode_cr = str_replace("+"," ",$_GET[cr_txt]);

$query_data .=" AND (gl_barang.id LIKE '%%$decode_cr%%' OR gl_kelompok.kelompok LIKE '%%$decode_cr%%' OR gl_barang.barang LIKE '%%$decode_cr%%' OR gl_barang.keterangan LIKE '%%$decode_cr%%')";

}

if(isset($_GET[cr_kel]) AND $_GET[cr_kel]<>'ALL') { 

$query_data .=" AND gl_barang.kelompok ='$_GET[cr_kel]'";

}

$query_data .=" ORDER BY gl_kelompok.kelompok, gl_barang.barang";

$query_limit_data = sprintf("%s LIMIT %d, %d", $query_data, $startRow_data, $maxRows_data);

$data = mysql_query($query_data, $con_gl) or die(mysql_error());

$totalRows_data = mysql_num_rows($data);

$totalPages_data = floor($totalRows_data / $maxRows_data);

$query_data .=" LIMIT $startRow_data, $maxRows_data";

$data = mysql_query($query_data, $con_gl) or die(mysql_error());

$totalRow_data = mysql_num_rows($data);

$row_data = mysql_fetch_assoc($data);



$queryString_data = "";

if (!empty($_SERVER['QUERY_STRING'])) {

  $params = explode("&", $_SERVER['QUERY_STRING']);

  $newParams = array();

  foreach ($params as $param) {

    if (stristr($param, "pageNum_data") == false && 

        stristr($param, "totalRows_data") == false) {

      array_push($newParams, $param);

    }

  }

  if (count($newParams) != 0) {

    $queryString_data = "&" . htmlentities(implode("&", $newParams));

  }

}

$queryString_data = sprintf("&totalRows_data=%d%s", $totalRows_data, $queryString_data);

include('include/widget_exportdata.php');

?>

<style>

#pricelist tr td {

	font-size:9px;	

}

</style>

<h1>Data Barang/Jasa</h1>

<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable"> 

  <tr valign="top" bgcolor="#FFFFFF" class="hide">

        <td><?php if(strstr($_SESSION[akses],"PD-3-1")) { ?><a href="index.php?component=barang&task=add"><img src="images/add_new.png" border="0" /></a><?php } ?></td>

        <td colspan="3" align="right" style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;"><form id="search" name="search" method="post" action="">

      <label>

      <select name="cr_kel" id="cr_kel" onchange="cr_txt.value=''">

        <option value="ALL" <?php if (!(strcmp("ALL", $_GET[cr_kel]))) {echo "selected=\"selected\"";} ?>>Pilih Kelompok Barang/Jasa</option>

        <?php

do {  

?>

        <option value="<?php echo $row_l_kel['id']?>"<?php if (!(strcmp($row_l_kel['id'], $_GET[cr_kel]))) {echo "selected=\"selected\"";} ?>><?php echo $row_l_kel['kelompok']?></option>

        <?php

} while ($row_l_kel = mysql_fetch_assoc($l_kel));

  $rows = mysql_num_rows($l_kel);

  if($rows > 0) {

      mysql_data_seek($l_kel, 0);

	  $row_l_kel = mysql_fetch_assoc($l_kel);

  }

?>

      </select>

      </label>

<label>

      <input name="cr_txt" type="text" id="cr_txt" placeholder="Find by: kelompok, barang, keterangan"; onclick="this.value='';"<?php echo $_REQUEST['cr_txt'];?>" size="40" maxlength="100" />

      </label>

      <label>

      <input name="Search" type="submit" id="Search" value="Search" />

      </label>

    </form>

	<?php

	if(isset($_POST['Search'])) {

		echo "<script>window.location=\"index.php?component=barang&cr_kel=".$_POST[cr_kel]."&cr_txt=".str_replace(" ","+",$_POST[cr_txt])."\";</script>";

	}

	?></td>

  </tr>

  <tr>

    <th width="20%"><strong>Kelompok Barang/Jasa </strong></th>

    <th width="25%"><strong>Barang/Jasa</strong></th>

    <th><strong>Keterangan</strong></th>

    <th width="125" align="center" class="hide"><strong>Aksi</strong></th>

  </tr>

  <?php if($totalRows_data > 0) { ?>

  <?php do { ?>

    <tr valign="top" bgcolor="#FFFFFF">

      <td><?php echo $row_data['kelompok']; ?></td>

      <td><?php echo $row_data['barang']; ?></td>

      <td><?php echo $row_data['keterangan']; ?></td>

      <td align="center" class="hide"><?php if(strstr($_SESSION[akses],"PD-3-2")) { ?><a href="index.php?component=barang&amp;task=edit&amp;id=<?php echo $row_data['id']; ?>"><img src="images/edit_.png" border="0"/></a><?php } ?> <?php if(strstr($_SESSION[akses],"PD-3-3")) { ?><a href="index.php?component=barang&amp;task=delete&amp;id=<?php echo $row_data['id']; ?>" class="ask"><img src="images/delete_.png" border="0" /></a><?php } ?></td>

    </tr>
    <?php } while ($row_data = mysql_fetch_assoc($data)); ?>
	<?php if($totalRows_data > $maxRows_data) { ?>
    <tr class="hide">
      <td colspan="10"><table border="0" align="left" width="50%">
          <tr>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="First.gif" border=0 ></a>
                <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="Previous.gif" border=0></a>
                <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="Next.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="Last.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
			<td width="88%">Halaman : <?php echo $pageNum_data+1; ?>, Ditampilkan <?php echo $totalRow_data; ?> dari <?php echo $totalRows_data; ?> total data</td>
          </tr>
        </table></td>
    </tr>
	<?php } ?>
   <?php }else{ ?>

  <tr bgcolor="#FFFFFF">

    <td colspan="4">Data tidak ada !!! </td>

  </tr>

  <?php } ?>

  <tr class="hide">

    <td colspan="4"><?php if(strstr($_SESSION[akses],"PD-3-1")) { ?><a href="index.php?component=barang&task=add"><img src="images/add_new.png" border="0" /></a><?php } ?></td>

  </tr>

</table>





<?php

mysql_free_result($data);



mysql_free_result($l_kel);

?>

